import config from "../config.js";
import { toast } from "./common.js";

let timeout = 10000;
const baseUrl = config.baseUrl;

const request = (config) => {
  const isToken = ((config.headers || {}).isToken = false);

  return new Promise((resolve, reject) => {
    uni.uploadFile({
      method: config.method || "post",
      url: baseUrl + config.url,
      filePath: config.filePath,
      name: config.name || "file",
      formData: config.formData,
      success: (res) => {
        let result = JSON.parse(res.data);
        if (result.code === 200) {
          resolve(result);
        }
      },
      fail: (error) => {
        toast({
          title: "报错",
        });
      },
    });
  });
};

export default request;
